from selenium.webdriver.common.by import By
from common.Utils import ChatroomDriver

#消息与发送页面测试
class Infor:
    url=""
    driver=""
    def __init__(self):
        self.url = "http://127.0.0.1:8080/client.html"
        self.driver=ChatroomDriver.driver
        self.driver.get(self.url)
    #登录状态下
    def InforTestByLogin(self):
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.left > div.tab > div.tab-friend").click()
        self.driver.find_element(By.CSS_SELECTOR,"#friend-list > li:nth-child(1) > h4").click()
        #检查元素
        #输入框
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > textarea")
        #发送按钮
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > div.ctrl > button")

        #登录状态下正常发送信息
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > textarea").send_keys("hello")
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > div.ctrl > button").click()
        actual = self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > div.message-show > div:nth-child(14) > div > p").text
        assert actual == "hello"
        #屏幕截图
        ChatroomDriver.getScreeShot()

        #登录状态下异常发送信息
        #输入信息不点击发送按钮
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > textarea").send_keys("hello")
        # 屏幕截图
        ChatroomDriver.getScreeShot()

        #输入空白信息点击发送按钮
        self.driver.find_element(By.CSS_SELECTOR, "body > div.client-container > div > div.right > textarea").send_keys("")
        self.driver.find_element(By.CSS_SELECTOR,"body > div.client-container > div > div.right > div.ctrl > button").click()
        # 屏幕截图
        ChatroomDriver.getScreeShot()

# Infor=Infor()
# Infor.InforTestByLogin()



